package com.example.java.Service.Impl;

import com.example.java.Entity.User;
import com.example.java.Mapper.UserMapper;
import com.example.java.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("UserService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //    查询所有
    @Override
    public List<User> alluser(){
        return userMapper.alluser();
    }

    //    增加
    @Override
    public int addandedit(User user) {
        if (user.getId() == null) {//如果没有id，则表示新增
            return userMapper.insert(user);
        } else {//否则为修改
            return userMapper.updata(user);
        }
    }
    //    删除
    @Override
    public int deleteById(Integer id) {
        return userMapper.deleteById(id);
    }

    //    模糊查询
    @Override
    public List<User> getLike(String name){
        return userMapper.getLike(name);
    }
}
